using System;

namespace LDNS.SDK.Utilities
{
    /// <summary>
    /// 控制台辅助类，提供控制台窗口的显示和隐藏功能
    /// 作者：huobing
    /// </summary>
    public static class ConsoleHelper
    {
        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        private static extern IntPtr GetConsoleWindow();

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        private const int SW_HIDE = 0;
        private const int SW_SHOW = 5;

        /// <summary>
        /// 隐藏控制台窗口
        /// </summary>
        public static void HideConsoleWindow()
        {
            IntPtr consoleWindow = GetConsoleWindow();
            if (consoleWindow != IntPtr.Zero)
            {
                ShowWindow(consoleWindow, SW_HIDE);
            }
        }

        /// <summary>
        /// 显示控制台窗口
        /// </summary>
        public static void ShowConsoleWindow()
        {
            IntPtr consoleWindow = GetConsoleWindow();
            if (consoleWindow != IntPtr.Zero)
            {
                ShowWindow(consoleWindow, SW_SHOW);
            }
        }
    }
}